const requireDirectory = require('require-directory')
const Router = require('koa-router')
class InitManager {
  static initCore(app) {
    this.app = app
    this.loadRouter()
    this.loadHttpException()
    this.loadConfig()
  }

  static loadRouter() {
    console.log(`${process.cwd()}/app/api`)
    requireDirectory(module, `${process.cwd()}/app/api`, {
       visit: (obj)=> {
          if(obj instanceof Router) {
            this.app.use(obj.routes())
          }
       }
     })
   }
   static loadHttpException() {
      const errors = require('./http-exception')
      global.errs = errors
   }

   static loadConfig(path) {
      const configPath = path || process.cwd() + '/config/config.js'
      const config = require(configPath)
      global.config = config
   }

}
module.exports = InitManager